# -*- coding: utf-8 -*-
import sys, os

#sys.path.append("../..")
#sys.path.append("../../..")
os.environ['DJANGO_SETTINGS_MODULE'] = "dummysettings"

from a115.utils.utils import *

print "Running tests..."
a, b, c = empty_lists(3)
assert a==b==c==[]
assert dcml(3.14) == Decimal("3.14")
assert flatten([[1,2], [3,4], [5]]) == [1,2,3,4,5]
assert listor_([True, False, False]) == True
assert listor_([False, False, False]) == False
assert remove_if(lambda x: not(x%2), [1,2,3,4,5,6,7]) == [1,3,5,7]
assert chunk("abcdefg", 3) == ["abc", "def", "g"]
assert bg2datetime("16.1.1981 15:20") == datetime.datetime(1981,1,16,15,20)
assert bg2date("16/01/1981") == datetime.date(1981,1,16)
assert flatten_deep([[1,2], 3, [4, [5,6,7]]]) == [1,2,3,4,5,6,7]
assert split_num("12345678.43") == "12 345 678.43"
assert split_num(123456) == "123 456.00"
assert date2bg(datetime.datetime(1981, 1, 16, 15, 20)) == "16.01.1981 15:20"
assert date2bg(datetime.date(1981, 1, 16)) == "16.01.1981"
assert egn2bday("8101168002") == datetime.date(1981, 1, 16)
assert egn2age("8101168002", as_of=datetime.date(2009, 6, 13)) == 28
assert egn2age_exact("8101168002", as_of=datetime.date(2009, 6, 13)) == reldelta(years=28, months=4, days=28)
assert random_date(start_date=datetime.date(2009, 6, 01), end_date=datetime.date(2009, 6, 30)) >= datetime.date(2009,6,01)
assert random_date(start_date=datetime.date(2009, 6, 01), end_date=datetime.date(2009, 6, 30)) <= datetime.date(2009,6,30)
assert start_week(datetime.date(2009,6,13)) == datetime.date(2009,6,8)
assert end_week(datetime.date(2009,6,13)) == datetime.date(2009,6,14)
assert week_range(datetime.date(2009, 6, 30)) == (datetime.date(2009, 6, 29), datetime.date(2009, 7, 5))
assert month_length(datetime.date(2009, 2, 12)) == 28
assert start_month(datetime.date(2009, 2, 12)) == datetime.date(2009, 2, 1)
assert end_month(datetime.date(2008, 2, 12)) == datetime.date(2008, 2, 29)
assert month_range(datetime.date(2009, 6, 13)) == (datetime.date(2009, 6, 1), datetime.date(2009, 6, 30))
assert list(date_range(datetime.date(2009, 6, 29), datetime.date(2009, 7, 2))) == [datetime.date(2009, 6, 29), datetime.date(2009, 6, 30), datetime.date(2009, 7, 1), datetime.date(2009, 7, 2)]
assert add_to_date(datetime.date(2009,6,29), 1, 2, 3) == datetime.date(2010, 9, 1)
assert date_delta(datetime.date(2009,6,29), datetime.date(2010, 9, 1)) == (1,2,3)
assert smart_date_ratio(datetime.date(2008,1,16), datetime.date(2009,1,16), datetime.date(2010,1,16), datetime.date(2011,1,16)) == dcml(1)
assert dateratio(datetime.date(2008,1,16), datetime.date(2009,1,16), datetime.date(2010,1,16), datetime.date(2011,1,16)) > dcml(1)
assert which(lambda x: x>7, [5,3,6,4,9,5,10]) == 4
assert 5.3 |pct| 400 == dcml(21.2)
assert split_period(0, date(2009, 1, 1), date(2011, 12, 31)) == [datetime.date(2009, 1, 1)]
assert split_period(2, date(2009, 1, 15), date(2012, 1, 14)) == [datetime.date(2009, 1, 15), datetime.date(2009, 7, 15), datetime.date(2010, 1, 15), datetime.date(2010, 7, 15), datetime.date(2011, 1, 15), datetime.date(2011, 7, 15)]
assert split_period(2, date(2009, 1, 15), date(2012, 1, 14), f=True) == [datetime.date(2009, 1, 1), datetime.date(2009, 7, 1), datetime.date(2010, 1, 1), datetime.date(2010, 7, 1), datetime.date(2011, 1, 1), datetime.date(2011, 7, 1)]
assert str_until(" - ", "I am - Legend") == "I am"
assert str_after(" - ", "I am - Legend") == "Legend"
assert phonetize(u"Искам да ям щъркели с юфка!") == u"Iskam da iam shtyrkeli s iufka!"
assert mark_up(5.3, 945640.42) == dcml(995759.36226)
assert mark_down(5.3, 945640.42) == dcml(895521.47774)
assert subdict({'a':1, 'b':2, 'c':3, 'd':4, 'e':5}, 'bdef') == {'b': 2, 'd': 4, 'e': 5}
class C():
    attr1 = None
    attr2 = 5
    attr3 = "boo"
c = C()
set_from_dict(c, {"attr1":1, "attr2":2, "attr6":6}, ["attr1", "attr2"])
assert c.attr1 == 1
assert c.attr2 == 2
assert c.attr3 == "boo"
print "Passed all tests for: %s" % (sys.version)
